package objects;

import world.BodyID;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.tiled.TiledMap;
import com.badlogic.gdx.graphics.g2d.tiled.TiledObject;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;

public class ItemBlock extends AbstractObject {

	public ItemBlock(TiledMap tiledMap, World _world, int posX, int posY) {
		// super(_object);
		texture = new Texture(Gdx.files.internal("data/box.png"));
		texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
		sprite = new Sprite(texture, 0, 0, texture.getWidth(),
				texture.getHeight());
		spriteBatch = new SpriteBatch();
		this.type = BodyDef.BodyType.DynamicBody;
		this.position.set((float) posX / PIXELS_PER_METER,
				(480 / PIXELS_PER_METER) - (float) posY / PIXELS_PER_METER);
world = _world;
		body = world.createBody(this);

		body.setUserData(BodyID.BOX);
		PolygonShape jumperShape = new PolygonShape();
		jumperShape.setAsBox(sprite.getWidth() / (2 * PIXELS_PER_METER),
				sprite.getHeight() / (2 * PIXELS_PER_METER));

		body.setFixedRotation(true);

		FixtureDef fixtureDef = new FixtureDef();
		fixtureDef.shape = jumperShape;
		fixtureDef.density = 1.0f;
		fixtureDef.friction = 5.0f;

		body.createFixture(fixtureDef);
		jumperShape.dispose();
	}

}
